package zwxsrv

import (
	"time"

	"gitee.com/zevenfly/goutil/zweixin"
)

func RegTextHandler(h TextHandler) error {
	return gWxHandlerMan.addTextHandler(h)
}

func UnregTextHandler(h TextHandler) error {
	return gWxHandlerMan.delTextHandler(h)
}

func RegEventHandler(event string, h EventHandler) error {
	return gWxHandlerMan.setEventHandler(event, h)
}

func UnregEventHandler(event string, h EventHandler) error {
	return gWxHandlerMan.delEventHandler(event)
}

// 获取 token
func GetAccessTokenEx() (string, time.Time) {
	return gAccessTokenMan.GetEx()
}

func GetAccessToken() string {
	token, _ := GetAccessTokenEx()
	return token
}

// 以下是简单封装的，免得很多参数

func SendAdminText(msg string) (errcode int, err error) {
	return zweixin.TrySendText(GetAccessToken(), gCfg.AdminOpenID, msg)
}

func TrySendText(openID, text string) (errcode int, err error) {
	return zweixin.TrySendText(GetAccessToken(), openID, text)
}

func SendTextVarServer(openID, text string) (errcode int, err error) {
	return zweixin.ApiSendTextVarServer(GetAccessToken(), openID, text)
}
